/*
 * ============================================================================
 *
 * This file is part of the Rotoblin 2 project.
 *
 *  File:			rotoblin.NoEscapeTank.sp
 *  Type:			Module
 *  Description:	Remove escape tanks on final when vehicle incoming.
 *
 *  Copyright (C) 2012-2015 raziEiL <war4291@mail.ru>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * ============================================================================
 */

#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <left4dhooks>

#define		NET_TAG					"[NoEscTank]"

 		 



ConVar g_hEnableNoEscTank;

bool g_bEnableNoEscTank, g_bVehicleIncoming;



#define PLUGIN_NAME                   "l4d_NoEscapeTank"    //这里写插件名字
#define PLUGIN_AUTHOR                 "豆瓣酱な"                         //作者
#define PLUGIN_DESCRIPTION            "救援来临时，不会在出现 Tank."   //介绍
#define PLUGIN_VERSION                "1.1"
#define PLUGIN_URL                    "https://gitee.com/sweet-and-sour-bombs"  //网站


public Plugin myinfo =
{
    name        = PLUGIN_NAME,
    author      = PLUGIN_AUTHOR,
    description = PLUGIN_DESCRIPTION,
    version     = PLUGIN_VERSION,
    url         = PLUGIN_URL
}




public void OnPluginStart()
{
	g_hEnableNoEscTank	= CreateConVar("no_escape_tank", "1", "插件开关.", _, true, 0.0, true, 1.0);
	HookEvent("finale_escape_start", NET_ev_FinaleEscStart, EventHookMode_PostNoCopy);
	HookEvent("round_start", 	NET_ev_RoundStart, EventHookMode_PostNoCopy);
	
	
	HookConVarChange(g_hEnableNoEscTank, eConvarChanged);
	

}

public void OnMapStart()
{
	CvarsChanged();
}

public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
	CvarsChanged();
}

void CvarsChanged()
{
	g_bEnableNoEscTank = g_hEnableNoEscTank.BoolValue;

}



public void NET_ev_FinaleEscStart(Event event, const char[] name, bool dontBroadcast)
{
	//if(IsTankProhibit()) return;
	if (!g_bEnableNoEscTank) return;

	g_bVehicleIncoming = true;
}


public void NET_ev_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
	g_bVehicleIncoming = false;
}

// left4downtown
public Action L4D_OnSpawnTank(const float vecPos[3], const float vecAng[3])
{
	if(g_bEnableNoEscTank && g_bVehicleIncoming)
	{
		//PrintToChatAll("Blocking tank spawn...");
		return Plugin_Handled;
	}
	return Plugin_Continue;
}


/*
static bool:IsTankProhibit()//犧牲最後一關
{
	decl String:sMap[64];
	GetCurrentMap(sMap, 64);
	return StrEqual(sMap, "l4d_river03_port");
}*/